<template>
  <div class="order-container">
    <el-table :data="orderData"
      border
      style="width: 100%">
      <el-table-column prop="create_time"
        label="日期"
        width="180">
      </el-table-column>
      <el-table-column prop="user_nickname"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column prop="orderDetail[0].description"
        label="订单详情">
      </el-table-column>
      <el-table-column prop="opration"
        label="操作">
        <template v-slot="{row}">
          <el-button @click="pay(row)" :disabled="row.pay_status===0?false:true">去支付</el-button>

          <el-button icon="el-icon-delete"
            @click="del(row)">删除</el-button>
            <span >{{row.pay_status===0?"未支付":"已支付"}}</span>
        </template>
          
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import * as vipApi from "../../../../api/vip";
export default {
  data() {
    return {
      orderData: [],
    };
  },
  created() {
    vipApi.getOrderApi().then((res) => {
      console.log(res);
      if (res.data.state) {
        this.orderData = res.data.data;
        console.log(this.orderData);
      }
    });
  },
  methods: {
    del(row) {
      this.$confirm("确认要删除此订单?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          console.log(row);
          vipApi.delOrderApi(row.order_id).then((res) => {
            console.log(res)
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    pay(row){
      console.log(row)
      localStorage.setItem("vip-row",JSON.stringify(row.orderDetail[0]))
      let {product_id}=JSON.parse(localStorage.getItem('vip-row'))
      console.log(product_id,this.num)
      vipApi.getPreorderApi(product_id,this.num)
      .then(res=>{
        console.log(res)
        if(res.data.state){
          localStorage.setItem("order_id",res.data.order_id)
          this.$router.push({name:"pay"})
        }
      })
    }
  },
};
</script>